package br.edu.unifei.cct810.trabalho01.eventos;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.text.JTextComponent;

import br.edu.unifei.cct810.trabalho01.patterns.Command;

public class MyFocusListener implements FocusListener{

	@Override
	public void focusGained(FocusEvent e) {
		if(e.getSource() instanceof JTextComponent) {
			((JTextComponent)e.getSource()).setCaretPosition(0);
			((JTextComponent)e.getSource()).selectAll();
		}
	}

	@Override
	public void focusLost(FocusEvent e) {
		Command cmd = (Command)e.getSource();
		cmd.validar();
		if(e.getSource() instanceof JTextComponent) {
			((JTextComponent)e.getSource()).select(0,0);
		}
	}

}
